package com.googlecode.sere.core

import com.googlecode.sere.http.{Unauthorized, HttpRequest}

class TrivialAuthenticator(val fixedPassword: String) extends RequestInterceptor {
  
  def intercept(req: HttpRequest, base: InvocationData) = {
    req.authorizationHeader match {
      case Some((_, theUser, pass)) => {
        if (pass == fixedPassword) 
          base.copy(user = Some(theUser))
        else
          throw new Unauthorized
      }
      case None => base
    }
  }
}
